package down
{  
    import flash.display.Sprite;  
    import flash.external.ExternalInterface;  
    import flash.system.Capabilities;  
	
    public class Tools extends Sprite
	{  
		
        public function Tools() 
		{  
            //writeInfo.appendText("操作系统:"+Capabilities.os+"\n");  
            //writeInfo.appendText("操作系统语言:"+Capabilities.language+"\n");  
            //writeInfo.appendText("平台和版本信息:"+Capabilities.version+"\n\n");  
            //writeInfo.appendText("浏览器信息:"+getUa()+"\n");  
            //writeInfo.appendText("ie浏览器:"+getBrowser("ie")+"\n");  
            //writeInfo.appendText("FF浏览器:"+getBrowser("moz")+"\n");  
            //writeInfo.appendText("safari浏览器:"+getBrowser("safari")+"\n");  
            //writeInfo.appendText("Chrome浏览器:"+getBrowser("chrome")+"\n");  
            //writeInfo.appendText("opera浏览器:"+getBrowser("opera")+"\n\n");  
            //writeInfo.appendText("当前url路径:"+getUrl()+"\n");  
            //writeInfo.appendText("参数id:"+argument("id")+"\n");  
        }  
        //获取浏览器信息  
        public static function getUa():String
		{  
            var uaInfo:String = ExternalInterface.call("function BrowserAgent(){return navigator.userAgent;}");  
            return uaInfo;  
        }  
        //获取当前url路径  
        public static function getUrl():String
		{  
            var url:String = ExternalInterface.call("function getUrl(){return document.location.href;}");  
            return url;  
        }  
        //浏览器判断  
        public static function getBrowser(isBrowser:String):Boolean
		{  
            var isB:Boolean;  
            switch(isBrowser){  
                case "ie":  
                    return isB = ExternalInterface.call("function isBrow(){return /msie/.test(navigator.userAgent.toLowerCase());}");  
                    break;  
                case "moz":  
                    return isB = ExternalInterface.call("function isBrow(){return /gecko/.test(navigator.userAgent.toLowerCase());}");  
                    break;  
                case "safari":  
                    return isB = ExternalInterface.call("function isBrow(){return /safari/.test(navigator.userAgent.toLowerCase());}");  
                    break;  
                case "opera":  
                    return isB = ExternalInterface.call("function isBrow(){return /opera/.test(navigator.userAgent.toLowerCase());}");  
                case "chrome":  
                    return isB = ExternalInterface.call("function isBrow(){return /chrome/.test(navigator.userAgent.toLowerCase());}");  
                    break;  
                default :  
                    return isB = false;  
            }  
        }  
        //url参数分析  
        public static function argument(n:String):String
		{  
            var urlStr:String = getUrl();  
            var keyword:String;  
            var urlStrArray:Array = urlStr.substr(urlStr.search("\\?")+1).split("&");  
            for(var i:int = 0; i < urlStrArray.length; i++){  
                var key:Array =urlStrArray[i].split("=");  
                if(key[0]==n){  
                    keyword = key[1];  
                    break;  
                }  
            }  
            return keyword || "null";  
        } 
		
		public static function strTOobj(str:String,seg:String,inf:String):Object 
		{
			var arr:Array = str.split(seg);
			var obj:Object = new Object();
			for (var i:int = 0; i < arr.length; i++) {
				var key:String = "";
				var info:String = "";
				var strArr:String = arr[i];
				var s:String = "";
				var bool:Boolean = false;
				for (var j:int = 0; j < strArr.length; j++) {
					s = strArr.charAt(j);
					if (s == "{") continue;
					if (s == "}") continue;
					if (s == inf) {
						bool = true;
						continue;
					}
					if (bool) info += s;
					else key += s;
				}
				obj[key] = info;
				trace(key + "    " + info);
			}
			return obj;
		}
    }  
} 